package com.jneagle.xlstool.bzwgjmx.view.gui;

import com.dwarfeng.dutil.basic.cna.model.ReferenceModel;
import com.dwarfeng.dutil.basic.cna.model.obs.ReferenceAdapter;
import com.dwarfeng.dutil.basic.gui.swing.MappingTableModel;
import com.dwarfeng.dutil.basic.gui.swing.SwingUtil;
import com.dwarfeng.subgrade.stack.bean.key.LongIdKey;
import com.dwarfeng.subgrade.stack.exception.ServiceException;
import com.jneagle.xlstool.bzwgjmx.stack.bean.entity.RawErrorInfo;
import com.jneagle.xlstool.bzwgjmx.stack.bean.entity.RawPart;
import com.jneagle.xlstool.bzwgjmx.stack.bean.entity.RawPartData;
import com.jneagle.xlstool.bzwgjmx.stack.service.RawDataLoadService;
import com.jneagle.xlstool.bzwgjmx.stack.service.RawErrorInfoMaintainService;
import com.jneagle.xlstool.bzwgjmx.stack.service.RawPartDataMaintainService;
import com.jneagle.xlstool.bzwgjmx.stack.service.RawPartMaintainService;
import com.jneagle.xlstool.bzwgjmx.stack.structure.ProgressObserver;
import com.jneagle.xlstool.bzwgjmx.stack.structure.ProgressStatus;
import com.jneagle.xlstool.bzwgjmx.view.handler.I18nHandler;
import com.jneagle.xlstool.bzwgjmx.view.handler.MessageHandler;
import com.jneagle.xlstool.bzwgjmx.view.handler.ModalHandler;
import com.jneagle.xlstool.bzwgjmx.view.structure.ModalItem;
import com.jneagle.xlstool.bzwgjmx.view.structure.OperationStep;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.DependsOn;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.List;
import java.util.*;

/**
 * 原始数据导入面板。
 *
 * @author DwArFeng
 * @since 1.0.0
 */
@Component
@DependsOn("viewConfiguration")
public class RawDataImportPanel extends JPanel {

    private static final long serialVersionUID = 8345460573483255503L;
    private static final Logger LOGGER = LoggerFactory.getLogger(RawDataImportPanel.class);

    private final ApplicationContext ctx;

    private final RawDataLoadService rawDataLoadService;
    private final RawPartMaintainService rawPartMaintainService;
    private final RawPartDataMaintainService rawPartDataMaintainService;
    private final RawErrorInfoMaintainService rawErrorInfoMaintainService;

    private final I18nHandler i18nHandler;
    private final Locale uiLocale;
    private final ModalHandler modalHandler;
    private final ThreadPoolTaskExecutor executor;
    private final MessageHandler messageHandler;

    private final ReferenceModel<List<File>> rawFileModel;
    private final ReferenceModel<String> notificationModel;
    private final ReferenceModel<ProgressStatus> progressStatusModel;
    private final MappingTableModel<RawPart> rawPartTableModel;
    private final MappingTableModel<RawPartData> rawPartDataTableModel;
    private final MappingTableModel<RawErrorInfo> rawErrorInfoTableModel;
    private final ReferenceModel<Integer> rawDataSucceedCountModel;
    private final ReferenceModel<OperationStep> operationStepModel;

    private final RawFileInspectDialog rawFileInspectDialog;
    private final RawDataErrorDialog rawDataErrorDialog;

    private final JTextField loadFileTextField = new JTextField();
    private final JButton selectFileButton = new JButton();
    private final JButton inspectFileButton = new JButton();
    private final JButton loadFileButton = new JButton();
    private final JTextField resultTextField = new JTextField();
    private final JButton showErrorButton = new JButton();
    private final JTable rawPartTable = new JTable();
    private final JTable rawPartDataTable = new JTable();

    private final LoadFileObserver loadFileObserver = new LoadFileObserver();
    private final RawDataLoadObserver rawDataLoadObserver = new RawDataLoadObserver();
    private final RawPartDataErrorIndicatorTableModelListener rawPartDataErrorIndicatorTableModelListener
            = new RawPartDataErrorIndicatorTableModelListener();
    private final RawDataSuccessCountModelObserver rawDataSuccessCountModelObserver
            = new RawDataSuccessCountModelObserver();
    private final RawPartListSelectionListener rawPartListSelectionListener
            = new RawPartListSelectionListener();

    private boolean rawPartSelectionAdjusting = false;

    public RawDataImportPanel(
            ApplicationContext ctx,
            RawDataLoadService rawDataLoadService,
            RawPartMaintainService rawPartMaintainService,
            RawPartDataMaintainService rawPartDataMaintainService,
            RawErrorInfoMaintainService rawErrorInfoMaintainService,
            I18nHandler i18nHandler,
            Locale uiLocale,
            ModalHandler modalHandler,
            ThreadPoolTaskExecutor executor,
            MessageHandler messageHandler,
            @Qualifier("rawFileModel") ReferenceModel<List<File>> rawFileModel,
            @Qualifier("notificationModel") ReferenceModel<String> notificationModel,
            @Qualifier("progressStatusModel") ReferenceModel<ProgressStatus> progressStatusModel,
            @Qualifier("rawPartTableModel") MappingTableModel<RawPart> rawPartTableModel,
            @Qualifier("rawPartDataTableModel") MappingTableModel<RawPartData> rawPartDataTableModel,
            @Qualifier("rawErrorInfoTableModel") MappingTableModel<RawErrorInfo> rawErrorInfoTableModel,
            @Qualifier("rawDataSucceedCountModel") ReferenceModel<Integer> rawDataSucceedCountModel,
            @Qualifier("operationStepModel") ReferenceModel<OperationStep> operationStepModel,
            RawFileInspectDialog rawFileInspectDialog,
            RawDataErrorDialog rawDataErrorDialog
    ) {
        this.ctx = ctx;
        this.rawDataLoadService = rawDataLoadService;
        this.rawPartMaintainService = rawPartMaintainService;
        this.rawPartDataMaintainService = rawPartDataMaintainService;
        this.rawErrorInfoMaintainService = rawErrorInfoMaintainService;
        this.i18nHandler = i18nHandler;
        this.uiLocale = uiLocale;
        this.modalHandler = modalHandler;
        this.executor = executor;
        this.messageHandler = messageHandler;
        this.notificationModel = notificationModel;
        this.progressStatusModel = progressStatusModel;
        this.rawPartTableModel = rawPartTableModel;
        this.rawPartDataTableModel = rawPartDataTableModel;
        this.rawErrorInfoTableModel = rawErrorInfoTableModel;
        this.rawDataSucceedCountModel = rawDataSucceedCountModel;
        this.operationStepModel = operationStepModel;
        this.rawFileInspectDialog = rawFileInspectDialog;
        this.rawFileModel = rawFileModel;
        this.rawDataErrorDialog = rawDataErrorDialog;
    }

    @SuppressWarnings("DuplicatedCode")
    @PostConstruct
    public void postConstruct() {
        // 初始化界面。
        GridBagLayout gridBagLayout = new GridBagLayout();
        gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0};
        gridBagLayout.rowHeights = new int[]{0, 0, 0};
        gridBagLayout.columnWeights = new double[]{0.0, 1.0, 0.0};
        gridBagLayout.rowWeights = new double[]{0.0, 0.0, 1.0};
        setLayout(gridBagLayout);

        JLabel loadFileLabel = new JLabel(i18nHandler.getMessage("ui.label.004"));
        GridBagConstraints gbcLoadFileLabel = new GridBagConstraints();
        gbcLoadFileLabel.insets = new Insets(0, 0, 0, 5);
        gbcLoadFileLabel.anchor = GridBagConstraints.EAST;
        gbcLoadFileLabel.gridx = 0;
        gbcLoadFileLabel.gridy = 0;
        add(loadFileLabel, gbcLoadFileLabel);

        selectFileButton.setAction(new SelectFileAction());
        selectFileButton.setText(i18nHandler.getMessage("ui.label.005"));
        GridBagConstraints gbcSelectFileButton = new GridBagConstraints();
        gbcSelectFileButton.insets = new Insets(0, 0, 0, 0);
        gbcSelectFileButton.fill = GridBagConstraints.BOTH;
        gbcSelectFileButton.gridx = 2;
        gbcSelectFileButton.gridy = 0;
        add(selectFileButton, gbcSelectFileButton);

        loadFileTextField.setEditable(false);
        GridBagConstraints gbcLoadFileTextField = new GridBagConstraints();
        gbcLoadFileTextField.insets = new Insets(0, 0, 0, 5);
        gbcLoadFileTextField.fill = GridBagConstraints.BOTH;
        gbcLoadFileTextField.gridx = 1;
        gbcLoadFileTextField.gridy = 0;
        add(loadFileTextField, gbcLoadFileTextField);

        inspectFileButton.setAction(new InspectFileAction());
        inspectFileButton.setText(i18nHandler.getMessage("ui.label.033"));
        GridBagConstraints gbcInspectFileButton = new GridBagConstraints();
        gbcInspectFileButton.insets = new Insets(0, 0, 0, 0);
        gbcInspectFileButton.fill = GridBagConstraints.BOTH;
        gbcInspectFileButton.gridx = 3;
        gbcInspectFileButton.gridy = 0;
        add(inspectFileButton, gbcInspectFileButton);

        loadFileButton.setAction(new LoadFileAction());
        loadFileButton.setText(i18nHandler.getMessage("ui.label.008"));
        GridBagConstraints gbcLoadFileButton = new GridBagConstraints();
        gbcLoadFileButton.insets = new Insets(0, 0, 0, 0);
        gbcLoadFileButton.fill = GridBagConstraints.BOTH;
        gbcLoadFileButton.gridx = 4;
        gbcLoadFileButton.gridy = 0;
        add(loadFileButton, gbcLoadFileButton);

        JLabel resultLabel = new JLabel(i18nHandler.getMessage("ui.label.018"));
        GridBagConstraints gbcResultLabel = new GridBagConstraints();
        gbcResultLabel.insets = new Insets(0, 0, 0, 5);
        gbcResultLabel.anchor = GridBagConstraints.EAST;
        gbcResultLabel.gridx = 0;
        gbcResultLabel.gridy = 1;
        add(resultLabel, gbcResultLabel);

        resultTextField.setEditable(false);
        GridBagConstraints gbcResultTextField = new GridBagConstraints();
        gbcResultTextField.insets = new Insets(0, 0, 0, 5);
        gbcResultTextField.fill = GridBagConstraints.BOTH;
        gbcResultTextField.gridx = 1;
        gbcResultTextField.gridy = 1;
        add(resultTextField, gbcResultTextField);

        showErrorButton.setAction(new ShowErrorDialogAction());
        showErrorButton.setText(i18nHandler.getMessage("ui.label.022"));
        GridBagConstraints gbcShowErrorButton = new GridBagConstraints();
        gbcShowErrorButton.insets = new Insets(0, 0, 0, 0);
        gbcShowErrorButton.fill = GridBagConstraints.BOTH;
        gbcShowErrorButton.gridwidth = 3;
        gbcShowErrorButton.gridx = 2;
        gbcShowErrorButton.gridy = 1;
        add(showErrorButton, gbcShowErrorButton);

        JPanel bodyPanel = new JPanel();
        GridBagLayout bodyPanelGridBagLayout = new GridBagLayout();
        bodyPanelGridBagLayout.columnWidths = new int[]{0, 0};
        bodyPanelGridBagLayout.rowHeights = new int[]{0, 0};
        bodyPanelGridBagLayout.columnWeights = new double[]{1.0, 2.0};
        bodyPanelGridBagLayout.rowWeights = new double[]{0, 1.0};
        bodyPanel.setLayout(bodyPanelGridBagLayout);
        GridBagConstraints gbcBodyPanel = new GridBagConstraints();
        gbcBodyPanel.insets = new Insets(5, 0, 0, 0);
        gbcBodyPanel.fill = GridBagConstraints.BOTH;
        gbcBodyPanel.gridwidth = 5;
        gbcBodyPanel.gridx = 0;
        gbcBodyPanel.gridy = 2;
        add(bodyPanel, gbcBodyPanel);

        JLabel rawPartLabel = new JLabel(i18nHandler.getMessage("ui.label.067"));
        GridBagConstraints gbcRawPartLabel = new GridBagConstraints();
        gbcRawPartLabel.insets = new Insets(0, 5, 0, 0);
        gbcRawPartLabel.fill = GridBagConstraints.BOTH;
        gbcRawPartLabel.gridx = 0;
        gbcRawPartLabel.gridy = 0;
        bodyPanel.add(rawPartLabel, gbcRawPartLabel);

        JLabel rawPartDataLabel = new JLabel(i18nHandler.getMessage("ui.label.068"));
        GridBagConstraints gbcRawPartDataLabel = new GridBagConstraints();
        gbcRawPartDataLabel.insets = new Insets(0, 5, 0, 0);
        gbcRawPartDataLabel.fill = GridBagConstraints.BOTH;
        gbcRawPartDataLabel.gridx = 1;
        gbcRawPartDataLabel.gridy = 0;
        bodyPanel.add(rawPartDataLabel, gbcRawPartDataLabel);

        I18nTableCellRenderer rawPartHeaderRender = ctx.getBean(
                I18nTableCellRenderer.class, ctx.getBean(I18nHandler.class),
                rawPartTable.getTableHeader().getDefaultRenderer()
        );
        rawPartTable.getTableHeader().setDefaultRenderer(rawPartHeaderRender);
        rawPartTable.setModel(rawPartTableModel);
        rawPartTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        JScrollPane rawPartScrollPane = new JScrollPane();
        rawPartScrollPane.setViewportView(rawPartTable);
        GridBagConstraints gbcRawPartScrollPane = new GridBagConstraints();
        gbcRawPartScrollPane.insets = new Insets(0, 0, 0, 0);
        gbcRawPartScrollPane.fill = GridBagConstraints.BOTH;
        gbcRawPartScrollPane.gridx = 0;
        gbcRawPartScrollPane.gridy = 1;
        bodyPanel.add(rawPartScrollPane, gbcRawPartScrollPane);

        I18nTableCellRenderer rawPartDataHeaderRender = ctx.getBean(
                I18nTableCellRenderer.class, ctx.getBean(I18nHandler.class),
                rawPartDataTable.getTableHeader().getDefaultRenderer()
        );
        rawPartDataTable.getTableHeader().setDefaultRenderer(rawPartDataHeaderRender);
        rawPartDataTable.setModel(rawPartDataTableModel);
        JScrollPane rawPartDataScrollPane = new JScrollPane();
        rawPartDataScrollPane.setViewportView(rawPartDataTable);
        GridBagConstraints gbcRawPartDataScrollPane = new GridBagConstraints();
        gbcRawPartDataScrollPane.insets = new Insets(0, 0, 0, 0);
        gbcRawPartDataScrollPane.fill = GridBagConstraints.BOTH;
        gbcRawPartDataScrollPane.gridx = 1;
        gbcRawPartDataScrollPane.gridy = 1;
        bodyPanel.add(rawPartDataScrollPane, gbcRawPartDataScrollPane);

        // 添加侦听器。
        rawFileModel.addObserver(loadFileObserver);
        rawErrorInfoTableModel.addTableModelListener(rawPartDataErrorIndicatorTableModelListener);
        rawDataSucceedCountModel.addObserver(rawDataSuccessCountModelObserver);
        rawPartTable.getSelectionModel().addListSelectionListener(rawPartListSelectionListener);

        // 同步属性。
        syncProperties();
    }

    private void syncProperties() {
        SwingUtil.invokeInEventQueue(() -> {
            loadFileTextField.setText("");
            loadFileButton.setEnabled(false);
            resultTextField.setText(i18nHandler.getMessage(
                    "ui.label.019", new Object[]{rawDataSucceedCountModel.get(), rawErrorInfoTableModel.size()}
            ));
            showErrorButton.setEnabled(!rawErrorInfoTableModel.isEmpty());
        });
    }

    @PreDestroy
    public void preDestroy() {
        // 移除侦听器。
        rawFileModel.removeObserver(loadFileObserver);
        rawPartDataTableModel.removeTableModelListener(rawPartDataErrorIndicatorTableModelListener);
        rawDataSucceedCountModel.removeObserver(rawDataSuccessCountModelObserver);
        rawPartTable.getSelectionModel().removeListSelectionListener(rawPartListSelectionListener);
    }

    public void loadData() {
        // 清除表格的选择。
        rawPartSelectionAdjusting = true;
        rawPartTableModel.clear();
        rawPartDataTableModel.clear();
        rawErrorInfoTableModel.clear();
        executor.submit(() -> {
            try {
                List<RawPart> rawPartList = rawPartMaintainService.lookupAsList();
                rawDataSucceedCountModel.set(rawPartDataMaintainService.lookupAsList().size());
                List<RawErrorInfo> rawErrorInfoList = rawErrorInfoMaintainService.lookupAsList();
                rawPartTableModel.addAll(rawPartList);
                rawErrorInfoTableModel.addAll(rawErrorInfoList);
            } catch (Exception e) {
                messageHandler.error(this, "ui.label.031");
            } finally {
                rawPartSelectionAdjusting = false;
            }
        });
    }

    @SuppressWarnings("DuplicatedCode")
    public void loadChildData() {
        rawPartDataTableModel.clear();
        LongIdKey rawPartKey = rawPartTableModel.get(rawPartTable.getSelectionModel().getAnchorSelectionIndex()).getKey();
        executor.submit(() -> {
            try {
                List<RawPartData> rawPartDataList = rawPartDataMaintainService.lookupAsList(
                        RawPartDataMaintainService.CHILD_FOR_RAW_PART, new Object[]{rawPartKey}
                );
                rawPartDataTableModel.addAll(rawPartDataList);
            } catch (Exception e) {
                messageHandler.error(this, "ui.label.031");
            }
        });
    }

    private class LoadFileObserver extends ReferenceAdapter<List<File>> {

        @Override
        public void fireSet(List<File> oldValue, List<File> newValue) {
            SwingUtil.invokeInEventQueue(() -> {
                if (newValue.isEmpty()) {
                    loadFileTextField.setText("");
                    loadFileButton.setEnabled(false);
                } else {
                    String path = newValue.get(0).getAbsolutePath();
                    if (newValue.size() > 1) {
                        path += "...";
                    }
                    loadFileTextField.setText(path);
                    loadFileButton.setEnabled(true);
                }
            });
        }
    }

    private class SelectFileAction extends AbstractAction {

        private static final long serialVersionUID = -2591375215965053105L;

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                // 创建文件选择器并进行设置。
                JFileChooser jfc = new JFileChooser();
                jfc.setLocale(uiLocale);
                jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
                jfc.setFileFilter(new FileNameExtensionFilter(i18nHandler.getMessage("ui.label.034"), "txt"));
                jfc.setAcceptAllFileFilterUsed(false);
                jfc.setMultiSelectionEnabled(true);
                // 设置默认路径为模态处理器对应的路径。
                File directory = modalHandler.getParsedValidValue(
                        ModalItem.MODAL_RAW_DATA_LAST_LOAD_DIRECTORY, File.class
                );
                if (!directory.isDirectory()) {
                    directory = directory.getParentFile();
                }
                jfc.setCurrentDirectory(directory);
                // 显示界面，让用户选择文件。
                int result = jfc.showOpenDialog(RawDataImportPanel.this);
                // 如果用户按下了确定键，则将文件模型设置为用户选择的文件。
                if (Objects.equals(result, JFileChooser.APPROVE_OPTION)) {
                    // 获取选择的所有文件。
                    File[] selectedFiles = jfc.getSelectedFiles();
                    // 设置文件模型的值为当前值。
                    rawFileModel.set(Collections.unmodifiableList(Arrays.asList(selectedFiles)));
                }
            } catch (Exception ex) {
                LOGGER.warn("选择文件时发生异常，异常信息如下: ", ex);
                messageHandler.error(RawDataImportPanel.this, "ui.label.009");
            }
        }
    }

    private class InspectFileAction extends AbstractAction {

        private static final long serialVersionUID = -2007419240121455940L;

        @Override
        public void actionPerformed(ActionEvent e) {
            rawFileInspectDialog.setLocationRelativeTo(ctx.getBean(MainFrame.class));
            rawFileInspectDialog.setVisible(true);
        }
    }

    private class LoadFileAction extends AbstractAction implements Runnable {

        private static final long serialVersionUID = 408384189921709149L;

        @Override
        public void actionPerformed(ActionEvent e) {
            // 在后台线程中执行方法，避免前端界面卡顿。
            executor.execute(this);
        }

        @Override
        public void run() {
            try {
                // 通过控制按钮的 enabled 属性，此处可以保证按钮按下时文件至少有一个。
                List<File> files = rawFileModel.get();

                // 取出第一个文件，设置模态处理器目录为指定文件的目录。
                modalHandler.setParsedValue(ModalItem.MODAL_RAW_DATA_LAST_LOAD_DIRECTORY, files.get(0).getParentFile());

                // 更新通知面板标签文本。
                notificationModel.set(i18nHandler.getMessage("ui.label.039"));

                // 创建侦听
                rawDataLoadService.addObserver(rawDataLoadObserver);

                // 调用接口读取文件，并捕获异常。
                try {
                    rawDataLoadService.load(files);
                } catch (ServiceException e) {
                    messageHandler.warn(RawDataImportPanel.this, "ui.label.015");
                    // 更新通知面板标签文本。
                    notificationModel.set(i18nHandler.getMessage("ui.label.013"));
                    return;
                } finally {
                    // 移除侦听。
                    rawDataLoadService.removeObserver(rawDataLoadObserver);
                }

                // 重新加载结构化数据。
                loadData();

                // 判断是否存在数据错误，如果有错误，则需要自动弹出错误对话框。
                if (rawErrorInfoTableModel.isEmpty()) {
                    notificationModel.set(i18nHandler.getMessage("ui.label.042"));
                } else {
                    notificationModel.set(i18nHandler.getMessage("ui.label.043"));
                }

                // 更新前端界面的操作步骤。
                operationStepModel.set(OperationStep.DATA_CONFIRM);
            } catch (Exception ex) {
                LOGGER.warn("加载文件时发生异常，异常信息如下: ", ex);
                messageHandler.error(RawDataImportPanel.this, "ui.label.011");
                operationStepModel.set(OperationStep.RAW_DATA_IMPORT);
            }
        }
    }

    private class RawDataLoadObserver implements ProgressObserver {

        @Override
        public void onProgressChanged(ProgressStatus progressStatus) {
            progressStatusModel.set(progressStatus);
        }
    }

    private class RawPartDataErrorIndicatorTableModelListener implements TableModelListener {

        @Override
        public void tableChanged(TableModelEvent e) {
            SwingUtil.invokeInEventQueue(() -> {
                resultTextField.setText(i18nHandler.getMessage(
                        "ui.label.019", new Object[]{rawDataSucceedCountModel.get(), rawErrorInfoTableModel.size()}
                ));
                showErrorButton.setEnabled(rawErrorInfoTableModel.size() > 0);
            });
        }
    }

    private class RawDataSuccessCountModelObserver extends ReferenceAdapter<Integer> {

        @Override
        public void fireSet(Integer oldValue, Integer newValue) {
            SwingUtil.invokeInEventQueue(() -> resultTextField.setText(i18nHandler.getMessage(
                    "ui.label.019", new Object[]{rawDataSucceedCountModel.get(), rawErrorInfoTableModel.size()}
            )));
        }
    }

    private class ShowErrorDialogAction extends AbstractAction {

        private static final long serialVersionUID = 3811304146007917902L;

        @Override
        public void actionPerformed(ActionEvent e) {
            rawDataErrorDialog.setLocationRelativeTo(ctx.getBean(MainFrame.class));
            rawDataErrorDialog.setVisible(true);
        }
    }

    private class RawPartListSelectionListener implements ListSelectionListener {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting() || rawPartSelectionAdjusting) {
                return;
            }
            loadChildData();
        }
    }
}
